/*
 * ProcessTest.java
 *
 * Created on Sobota, 2007, november 17, 17:25
 */

package gui;

import java.io.IOException;
import java.io.InputStream;
import logic.SimulationParameters;
import logic.gridSimInterface.SimTags;
import logic.schedulers.AlgorithmCollection;

/**
 *
 * @author  alvin
 */
public class ProcessTest extends javax.swing.JFrame {
    
    /** Creates new form ProcessTest */
    public ProcessTest() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jButton1)
                .addContainerGap(176, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jButton1)
                .addContainerGap(247, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        AlgorithmCollection.loadAlgorithms();
        SimulationParameters.setPlanningType(SimTags.DYNAMIC_PLANNING);
        SimulationParameters.setCostFunction(SimTags.COST_BY_LATENCY);
        SimulationParameters.setLocalScheduler(AlgorithmCollection.getLocalScheduling(2));
        SimulationParameters.setGlobalScheduler(AlgorithmCollection.getGlobalScheduling(0));
        
        String paramsFile = "/home/alvin/programy/java/GangstersGrid/params.txt";
        try {
            SimulationParameters.saveToFile(paramsFile);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        String fileSep = System.getProperty("file.separator");
        String javaPath = System.getProperty("java.home") + fileSep +
                "bin" + fileSep + "java";
        
        ProcessBuilder pb = new ProcessBuilder(
                javaPath,
                "-cp",
                System.getProperty("java.class.path"),
                "logic.SimulationRun",
                "/home/alvin/test_topology.xml",
                paramsFile,
                "/home/alvin/programy/java/GangstersGrid/sub1.xml");
        System.out.println("System.class.path = " + System.getProperty("java.class.path"));
        pb = pb.redirectErrorStream(true);
        try {
            Process p = pb.start();
            System.out.println("pb.start() finished");
            try {
                p.waitFor();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            System.out.println("waitFor() finished");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        System.out.println("actionPerformed() finished");
    }//GEN-LAST:event_jButton1ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ProcessTest().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables
    
}
